package ranab.jar;

import java.util.Date;
import java.util.zip.ZipEntry;

/**
 * Compare two zip entries based on the file name.
 *
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public 
class ZipModificationTimeComparator extends ZipComparator  {
    
    public int compare(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        Date dt1 = new Date(z1.getTime());
        Date dt2 = new Date(z2.getTime());
        return dt1.compareTo(dt2);
    }
    
    public boolean equals(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        return z1.getTime() == z2.getTime();
    }
    
    
    /**
     * get header name
     */
     public String getHeaderName()  {
         return "Modification Time";
     }
}
